

<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('title'); ?>
	Media Performance
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>
		<div id="content" class="box">
			<h1>Media Performance</h1>
            <form method="get" action="<?php echo url('report/media'); ?>">
            	<select id="reporttype" name="reporttype">
                   	<option disabled="disabled">---Publisher report---</option>
					<option value="0" <?php echo (isset($reporttype) && $reporttype=="0") ? 'selected="selected"' : '';?>>Media Performance Report</option>
					<option value="1" <?php echo (isset($reporttype) && $reporttype=="1") ? 'selected="selected"' : '';?>>Site Performance Report</option>
				</select>
              	<select id="hourly" name="hourly">
                   	<option disabled="disabled">---Hourly---</option>
					<option value="0" <?php echo (isset($hourly) && $hourly=="0") ? 'selected="selected"' : '';?>>Hourly</option>
					<option value="1" <?php echo (isset($hourly) && $hourly=="1") ? 'selected="selected"' : '';?>>Daily</option>
					<option value="2" <?php echo (isset($hourly) && $hourly=="2") ? 'selected="selected"' : '';?>>Weekly</option>
              		<option value="3" <?php echo (isset($hourly) && $hourly=="3") ? 'selected="selected"' : '';?>>Monthly</option>
				</select>
               	<select id="duration" name="duration">
                 	<option disabled="disabled">---Duration---</option>
					<option value="0" <?php echo (isset($duration) && $duration=="0") ? 'selected="selected"' : '';?>>Today</option>
                  	<option value="1" <?php echo (isset($duration) && $duration=="1") ? 'selected="selected"' : '';?>>Yesterday</option>
                  	<option value="2" <?php echo (isset($duration) && $duration=="2") ? 'selected="selected"' : '';?>>Week To Day</option>
                   	<option value="3" <?php echo (isset($duration) && $duration=="3") ? 'selected="selected"' : '';?>>Month To Day</option>
                 	<option value="4" <?php echo (isset($duration) && $duration=="4") ? 'selected="selected"' : '';?>>Custom Date Range</option>
				</select>
                <script type="text/javascript">
					$("#duration").change(function(){
						if($("#duration").val()==4){
							$("#customdaterange").slideDown();	
						}else{
							$("#customdaterange").slideUp();
						}
					});
				</script>
              	<span id="customdaterange" <?php echo (isset($duration) && $duration=="4") ? '' : 'style="display:none;"';?> >
                  	<span>From</span><input type="text" id="startdate" name="startdate" class="myDatePickerClass" readonly="readonly" />
                   	<span>To</span><input type="text" id="enddate" name="enddate" class="myDatePickerClass" readonly="readonly" />
                   	<script type="text/javascript">
                       	$(".myDatePickerClass").datepicker({
                           	dateFormat:'yy-mm-dd',
                           	changeYear: true,
                           	changeMonth: true,
                        	showMonthAfterYear: true,
                    	})
                	</script>
                </span>
                <input type="submit" name="submit" value="Generate Report" />
            </form>
            
			<form method="get" action="<?php echo url('report/media'); ?>" <?php echo empty($filters)? "style='display:none;'":"" ?>>    
				<div class="filter">
                    <select id="mediatype" name="mediatype">
                        <option disabled="disabled">---Media Type---</option>
                        <?php foreach($filters['mt'] as $k=>$mt){ ?>
                        	<option value="<?php echo $k; ?>"><?php echo $mt; ?></option>
                        <?php } ?>
                    </select>
                    <select id="buytype" name="buytype">
                        <option disabled="disabled">---Buy Type---</option>
                        <?php foreach($filters['bt'] as $k=>$bt){ ?>
                        	<option value="<?php echo $k; ?>"><?php echo $bt; ?></option>
                        <?php } ?>
                    </select>
                    <select id="publisher" name="publisher">
                        <option disabled="disabled">---Publisher---</option>
                        <?php foreach($filters['pub'] as $k=>$pub){ ?>
                        	<option value="<?php echo $k; ?>"><?php echo $pub; ?></option>
                        <?php } ?>
                    </select>
                    <select id="creative" name="creative">
                        <option disabled="disabled">---Creative---</option>
                        <?php foreach($filters['cre'] as $k=>$cre){ ?>
                        	<option value="<?php echo $k; ?>"><?php echo $cre; ?></option>
                        <?php } ?>
                    </select>
                    <select id="campaign" name="campaign">
                        <option disabled="disabled">---Campaign---</option>
                        <?php foreach($filters['cam'] as $k=>$cam){ ?>
                        	<option value="<?php echo $k; ?>"><?php echo $cam; ?></option>
                        <?php } ?>
                    </select>
					<input type="submit" value="Update" />
				</div>
			</form>
			<table class="full-size">
				<thead>
					<tr>
						<th>Start Date</th>
						<th>End Date</th>
						<th>Buy Type</th>
						<th>Publisher Type</th>
						<th>Publisher</th>
						<th>Campaign</th>
						<th>Placement</th>
						<th>Creative</th>
						<th>Destination URL</th>
						<th>Impression</th>
						<th>Click</th>
						<th>Leads</th>
						<th>Conversions</th>
						<th>Revenue</th>
						<th>Cost</th>
						<!--  
						<th>Gross Profit</th>
						<th>GM</th>
						<th>ROAS</th>
						<th>CPM</th>
						<th>CPC</th>
						<th>CPL</th>
						<th>RPM</th>
						<th>RPC</th>
						<th>RPL</th>
						-->
					</tr>
				</thead>
				<tbody>
					<?php 
						if(!empty($reportItems)):						
							$durations = Util::getReportDuration($duration);
						    foreach ($reportItems as $reportItem):
					?>
							<tr>
								<td><?php echo $durations[0];?></td>
								<td><?php echo $durations[1];?></td>
								<td><?php echo $reportItem['buy_type'];?></td>
								<td><?php echo $reportItem['media_type'];?></td>
								<td><?php echo $reportItem['pub'];?></td>
								<td><?php echo $reportItem['cam'];?></td>
								<td><?php echo $reportItem['pla'];?></td>
								<td><?php echo $reportItem['cre'];?></td>
								<td><?php echo $reportItem['lu'];?></td>
								<td><?php echo $reportItem['impression'];?></td>
								<td><?php echo $reportItem['click'];?></td>
								<td><?php echo $reportItem['leads'];?></td>
								<td><?php echo $reportItem['conversion'];?></td>
								<td><?php echo $reportItem['revenue'];?></td>
								<td><?php echo $reportItem['cost'];?></td>
							</tr>
						<?php endforeach;?>
					<?php endif;?>
				</tbody>
			</table>
			
		</div>
<?php $this->_endblock(); ?>